import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Scanner;
public class Pay extends Product{
    ArrayList<Double>TotalMoney=new ArrayList<>();//某位顾客的总花费
    ArrayList<String>bought=new ArrayList<>();
    ArrayList<LocalDateTime>Time=new ArrayList<>();
    ShoppingCar shop=new ShoppingCar();
    double price=0;
    int count=0;
    double total=0;
    String shopName=null;
    private LocalDateTime paymentTime;
    public void payFor(ArrayList<Product>shoppingList) {
        while (true){
        System.out.println("请输入您想购买的商品名：");
        Scanner reader = new Scanner(System.in);
        shopName = reader.next();
        for(Product product:shoppingList){
        if (shopName.equals(product.getGoodsName())) {
            System.out.println("请选择支付方式：");
            System.out.println("1--微信");
            System.out.println("2--支付宝");
            System.out.println("3--银行卡");
        }}
            paymentTime = LocalDateTime.now();
            int payChoice = reader.nextInt();
            for (int i = 0; i < shoppingList.size(); i++) {
                Product goodsInCar = shoppingList.get(i);
                if (shopName.equals(goodsInCar.getGoodsName())) {
                    price = goodsInCar.getPrice();
                    count = goodsInCar.getNum();
                    shoppingList.remove(i);
                    break;
                }
            }
            total=count*price;
        switch (payChoice) {
            case 1://微信支付
                try {
                    System.out.println("是否确认支付？\n\t1--是\t2--否");
                    Scanner yee = new Scanner(System.in);
                    int yes = yee.nextInt();
                    switch (yes) {
                        case 1:
                            System.out.println("购买成功！");
                            bought.add(shopName);//记录购买的商品名
                            TotalMoney.add(price);//记录购买的商品总价
                            Time.add(paymentTime);//记录购买的时间
                            break;

                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case 2:
                try {
                    System.out.println("是否确认支付？\n\t1--是\t2--否");
                    Scanner yee = new Scanner(System.in);
                    int yes = yee.nextInt();
                    switch (yes) {
                        case 1:
                            System.out.println("购买成功！");
                            bought.add(shopName);//记录购买的商品名
                            TotalMoney.add(price);//记录购买的商品总价
                            Time.add(paymentTime);
                            break;
                        case 2: {
                            return;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            case 3:
                try {
                    System.out.println("是否确认支付？\n\t1--是\t2--否");
                    Scanner yee = new Scanner(System.in);
                    int yes = yee.nextInt();
                    switch (yes) {
                        case 1:
                            System.out.println("购买成功！");
                            bought.add(shopName);//记录购买的商品名
                            TotalMoney.add(price);//记录购买的商品总价
                            Time.add(paymentTime);
                            break;
                        case 2: {
                            return;
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
        }
                System.out.println("您是否要继续购买商品？" +
                        "(1、是；2、否)");
                int choose=reader.nextInt();
                if(choose==1){
                    continue;
                }else{
                    break;
                }
        }
    }
    public void showList(){
            System.out.printf("%-15s %-20s %-25s%n", "总金额", "已购买商品", "购买时间");
            System.out.println("---------------------------------------------------------");
            for (int i = 0; i < TotalMoney.size(); i++) {
                System.out.printf("%-15.2f %-20s %-25s%n", TotalMoney.get(i), bought.get(i), Time.get(i));
            }
        }
        public void changeCount(ArrayList<Product>goodsList){
        for(Product product:goodsList){
            if(shopName.equals(product.getGoodsName())){
                product.setNum(product.getNum()-count);
            }
        }
        }
    }

